package com.server;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.db.DB;
import com.tools.Constants;

public class S2S1LOGIN extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Override
	public void init() throws ServletException {
		Constants.init();
		System.out.println("DB name:" + Constants.DBNAME);
		DB.connDB();
		super.init();
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		Enumeration<String> er = request.getParameterNames();
		System.out.println("[S2S1] get begin");
		System.out.println("后台版本> 1");
		PrintWriter writer = response.getWriter();
		String id = null;
		String ps = null;
		
		
		while (er.hasMoreElements()) {
			String element = er.nextElement();
			if (element.equals("id")) {
				id = request.getParameterValues("id")[0];
				System.out.println("[S2S1] id:"+id);
			}
			if (element.equals("ps")) {
				ps = request.getParameterValues("ps")[0];
				System.out.println("[S2S1] ps:"+ps);
			}
		}
		if((id != null) && (ps != null) ){
			ResultSet rs =DB.select("select * from admin ;");
			try {
				while(rs.next()){
					String id1 = rs.getString("_id");
					String ps1 = rs.getString("ps");
					if(id1.equals(id) && ps1.equals(ps)){
						writer.println("http://115.238.95.2:8089/userrrr.html");
					}
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
 	}
}
